<script>

import * as echarts from 'echarts';
export default {
  name: 'VisualizationEight',
  data() {
    return{

    }
  },
  mounted() {
    this.getData();
  },
  methods: {
    getData() {
      this.$axios.get('/api/vis/data14', {

      }).then(res =>{
        if(res.data.code === 20041) {
          let data1 = [];
          let data2 = [];
          for (let i = 0; i < res.data.data.length; i++) {
            data1.push(
                res.data.data[i].param
            );
            data2.push(
                res.data.data[i].param1
            )
          }
          this.init(data1,data2)
        }
      }).catch(error =>{
        this.open4(error);
      })
    },
    open4(msg) {
      this.$notify.error({
        title: msg,
        message: '这是一条错误的提示消息'
      });
    },
    init(data1, data2) {
      var chartDom = document.getElementById('main12');
      var myChart = echarts.init(chartDom);
      var option;

      option = {
        title: {
          text: "5A景区年度评论统计",
        },
        grid: {
          containLabel: true,
          top: 30,
          right: 15,
          bottom: 0,
          left: 15
        },
        tooltip: {
          trigger: "axis",
          axisPointer: {
            type: 'shadow'
          },
          formatter: params => {
            console.log(params)
            const {
              name,
              data,
            } = params[0];
            return `
            <span style="font-size: 14px;font-family: Source Han Sans CN-Medium;font-weight: 500;color: #FFFFFF;margin-bottom:12px;">${name}</span>
            <sapn style="font-size: 14px;font-family: Source Han Sans CN-Medium;font-weight: 500;color: #FFFFFF;margin-bottom:4px;">：${data} 次</span>
         `
          },
          extraCssText: 'opacity: 0.8;background-color:#050F1B;padding:16px;box-shadow: 1px 6px 15px 1px rgba(0,0,0,0.13);border-radius: 4px;filter: blur(undefinedpx);border:none;'
        },
        xAxis: {
          name: "年度",
          // 类目轴
          type: "category",
          data: data1,
          axisTick: {
            show: false //隐藏X轴刻度
          },
          axisLine: {
            lineStyle: {
              color: "#CCCCCC"
            }
          },
          axisLabel: {
            show: true,
            textStyle: {
              color: '#000',
              fontSize: 14,
              fontFamily: 'Source Han Sans CN-Regular',
            }
          },
        },
        yAxis: {
          type: 'value',
          name: "年度评论人数",
          nameTextStyle: {
            color: 'rgba(0,0,0,0.65)',
            fontSize: 14,
            fontFamily: 'Source Han Sans CN-Regular',
            align: "left",
            verticalAlign: "center",
          },
          axisLabel: {
            color: 'rgba(0,0,0,0.65)',
            textStyle: {
              fontSize: 14
            },
          },
          axisLine: {
            show: false,
            lineStyle: {
              color: 'rgba(223, 223, 223, 1)',
            }
          },
          axisTick: {
            show: false
          },
          splitLine: {
            lineStyle: {
              color: 'rgba(223, 223, 223, 1)',
              type: "dashed",
            }
          }
        },
        series: [
          {
            type: "bar",
            barWidth: "50%",
            showBackground: true,
            backgroundStyle: {
              color: "transparent"
            },
            itemStyle: {
              color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
                { offset: 0, color: "#4B87FFFF" },
                { offset: 1, color: "#82BCFFFF" }
              ])
            },
            data: data2
          }
        ]
      }

      option && myChart.setOption(option);

    }
  }

}
</script>

<template>
  <div id="main12"></div>
</template>

<style scoped>
#main12 {
  width: 100%;
  height: 100%;
}
</style>